﻿using System;
using System.Text;
using BSharp.Compiler;
using BSharp.Compiler.Emit;

namespace BSharp
{
	class MainClass
	{
		public static void Main (string[] args)
		{//
			// FTFTTFFTTF
			string source = @"
main () {
	auto array[10];
	array [0] = 2;
	putint (*array);
}

putchar (c) {

}

putint (c) {

}

";
			ErrorLog errorLog = new ErrorLog ();
			Tokenizer scanner = new Tokenizer (errorLog, source);
			TokenStream stream = scanner.Scan ();

			BParser parser = new BParser (null);

			BSharpContext context = BSharpContext.Create ();

			var root = parser.Parse (stream);

			SemanticAnalyser anaylser = new SemanticAnalyser (context);
			var symbtab = anaylser.Analyse (root);

			BCompiler compiler = new BCompiler (context, symbtab);

			var result = compiler.Compile (root);
			StringBuilder test = new StringBuilder ();
			RaptorCompiler raptorC = new RaptorCompiler (test);

			result.CompileUnit (raptorC);

			Console.WriteLine (test.ToString ());

			Console.WriteLine (context.ErrorLog.ErrorCount);
			Console.WriteLine ("Hello World!");
		}
	}
}
